package com.kakarote.examine.constant;

import com.kakarote.core.common.enums.SystemCodeEnum;
import com.kakarote.core.exception.CrmException;

import java.util.Objects;

//处理结果方式
public enum PassFlagEnum {

    //同意类型
    //手动同意
    PASS_HANDLE(1, 101, "手动同意"),
    //审批人异常自动同意
    PASS_AUTO_NO_USER(1, 102, "审批人不存在异常自动同意"),
    PASS_AUTO_NO_VALID_USER(1, 104, "审批人无效异常自动同意"),
    //超时自动同意
    PASS_AUTO_OUT_TIME(1, 103, "超时自动同意"),

    //转发类型
    FORWARD_HANDLE(2, 201, "手动转交"),
    //审批人异常自动同意
    FORWARD_AUTO_NO_USER(2, 202, "审批人不存在异常自动转交"),
    //超时自动同意
    FORWARD_AUTO_OUT_TIME(2, 203, "超时自动转交"),
    FORWARD_AUTO_NO_VALID_USER(2, 204, "审批人无效异常自动转交"),
    //委托转交
    FORWARD_DELEGATE(2, 205, "委托转交"),
    //终止类型
    END_HANDLE(3, 301, "手动终止"),
    //审批人异常自动终止
    END_AUTO_NO_USER(3, 302, "审批人异常自动终止"),
    //超时自动终止
    END_AUTO_OUT_TIME(3, 303, "超时自动终止"),


    //被跳过，不在审批历史流程显示
    SKIP_ADMIN_HANDLE(4, 401, "被管理员操作跳过审批人"),

    SKIP_AUTO_NO_USER(1, 402, "审批人不存在异常自动跳过"),
    ;

    private PassFlagEnum(Integer code, Integer type, String desc) {
        this.code = code;
        this.type = type;
        this.desc = desc;
    }

    private Integer code;
    private Integer type;
    private String desc;

    public Integer getType() {
        return type;
    }

    public String getDesc() {
        return desc;
    }

    public static PassFlagEnum valueOf(Integer type) {
        for (PassFlagEnum handleTypeEnum : values()) {
            if (Objects.equals(type, handleTypeEnum.getType())) {
                return handleTypeEnum;
            }
        }
        throw new CrmException(SystemCodeEnum.SYSTEM_NO_VALID);
    }

}
